<?php
 
function hitung_total_rapel($karyawan_id , $periode_id){
	$query = "SELECT nominal FROM pr_rapel_komponen_karyawan
				WHERE  karyawan_id = {$karyawan_id} 
					AND  periode_prev_id = {$periode_id} 
					AND  komponen_id = 0";
	$result = my_query($query);
	$row = my_fetch_array($result);
	$rapel_gaji = $row['nominal'];
	
	$query = "SELECT SUM(a.nominal) as total_rapel 
				FROM pr_rapel_komponen_karyawan a 
				INNER JOIN pr_komponen_gaji b ON b.komponen_gaji_id = a.komponen_id AND a.komponen_id > 0
				WHERE a.karyawan_id = {$karyawan_id} AND a.periode_prev_id = {$periode_id} AND  b.tipe < 2 "; 
	$result = my_query($query);
	$row = my_fetch_array($result);
	$tunjangan = $row['total_rapel'];
	
	$query = "SELECT SUM(a.nominal) as total_rapel 
				FROM pr_rapel_komponen_karyawan a 
				INNER JOIN pr_komponen_gaji b ON b.komponen_gaji_id = a.komponen_id AND a.komponen_id > 0
				WHERE a.karyawan_id = {$karyawan_id} AND a.periode_prev_id = {$periode_id} AND  b.tipe = 2 ";
	$result = my_query($query);
	$row = my_fetch_array($result);
	$potongan = $row['total_rapel'];
	return ($rapel_gaji + $tunjangan  - $potongan);
}

function list_validasi(){
	$header = array(
		'NIK'=>array('style'=>'text-align:center;border-bottom:2px solid;width:10%'),  
		'Nama'=>array('style'=>'text-align:left;border-bottom:2px solid;width:35%'),  
		'Gaji Bulan Ini'=>array('style'=>'text-align:right;border-bottom:2px solid;width:15%'),  
		'Gaji Bulan Lalu'=>array('style'=>'text-align:right;border-bottom:2px solid;width:15%'),  
		'Selisih'=>array('style'=>'text-align:right;border-bottom:2px solid;width:15%'),  
		' '=>array('style'=>'border-bottom:2px solid;width:10%'), 
	);
	$end=get_batas_tmt() ;
	if(isset($_GET['key'])){
		$query = "
			SELECT a.karyawan_id FROM karyawan a 
			INNER JOIN kekaryawanan b ON b.karyawan_id = a.karyawan_id 
			INNER JOIN biodata c ON a.biodata_id = c.biodata_id 
			WHERE b.tmb  <= '{$end}' 
			AND a.karyawan_id NOT IN (select karyawan_id FROM karyawan_disable)
			AND a.karyawan_id NOT IN (select karyawan_id FROM pemberhentian  WHERE tmt <= '{$end}') 	
			AND ( c.nama LIKE '%{$_GET['key']}%' OR a.nik ='{$_GET['key']}' )
		";
	}else{	
		$query = " SELECT a.karyawan_id FROM karyawan a
				INNER JOIN kekaryawanan b ON b.karyawan_id = a.karyawan_id 
				WHERE b.tmb  <= '{$end}' 
				AND a.karyawan_id NOT IN (select karyawan_id FROM karyawan_disable)
				AND a.karyawan_id NOT IN (select karyawan_id FROM pemberhentian  WHERE tmt <= '{$end}') 	
			";	
	}
	 
	$result = my_query($query);
	$total_records = my_num_rows($result );
	$scroll_page =5;  
	$per_page =25;  
	$current_page = isset($_GET['page']) ? (int) $_GET['page'] : 1 ; 
	if($current_page < 1){
		$current_page = 1;
	}		 
	$pager_url  ="index.php?com={$_GET['com']}&task={$_GET['task']}&field={$_GET['field']}&key={$_GET['key']}&page=";	 
	$inactive_page_tag = 'style="padding:4px;background-color:#BBBBBB"';  
	$previous_page_text = ' Mundur '; 
	$next_page_text = ' Maju ';  
	$first_page_text = ' Awal '; 
	$last_page_text = ' Akhir ';
	
	$kgPagerOBJ = new kgPager();
	$kgPagerOBJ->pager_set(
		$pager_url, 
		$total_records, 
		$scroll_page, 
		$per_page, 
		$current_page, 
		$inactive_page_tag, 
		$previous_page_text, 
		$next_page_text, 
		$first_page_text, 
		$last_page_text ,$pager_url_last); 
				
	$result = my_query($query ." LIMIT ".$kgPagerOBJ->start.", ".$kgPagerOBJ->per_page); 	
	$row = array(); 
	$i = ($current_page  - 1 ) * 25; 
	
	$periode_id=get_periode_gaji() ;
	$last_periode_id=get_last_periode_id($periode_id) ;
	
	while($ey = my_fetch_array($result)){
		$karyawan = loaddata_karyawan($ey['karyawan_id']);

		$query = " SELECT gaji_dibayar FROM pr_gaji 
			WHERE periode_id=0
			AND karyawan_id=".$ey['karyawan_id']
		;
		$result1 = my_query($query);	
		$gajis = my_fetch_array($result1);
		$gaji_bl = $gaji_bi = 0;	
		if(	$gajis ){
			$gaji_bi = $gajis['gaji_dibayar'];				
		}
		$query = "SELECT SUM(a.kalkulasi) AS kalkulasi 		
			FROM pr_gaji_komponen a 
			LEFT JOIN pr_komponen_gaji b ON b.komponen_gaji_id=a.komponen_id
			WHERE a.karyawan_id=".$ey['karyawan_id']." 
			AND a.periode_id=0 
			AND b.tipe<3 ";
		$result1 = my_query($query);	
		$komponen_gajis = my_fetch_array($result1);
		if(	$komponen_gajis ){
			$gaji_bi+=$komponen_gajis['kalkulasi'];
			$rapel = hitung_total_rapel($ey['karyawan_id'] , $last_periode_id);
			$gaji_bi+=$rapel;
		}	
		

		$query = " SELECT gaji_dibayar FROM pr_gaji 
			WHERE periode_id=".($last_periode_id)."
			AND karyawan_id=".$ey['karyawan_id']
		;
		$result1 = my_query($query);	
		$gajis = my_fetch_array($result1);
		if(	$gajis ){
			$gaji_bl = $gajis['gaji_dibayar'];				
		}

		$query = "SELECT SUM(a.kalkulasi) AS kalkulasi 		
			FROM pr_gaji_komponen a 
			LEFT JOIN pr_komponen_gaji b ON b.komponen_gaji_id=a.komponen_id
			WHERE a.karyawan_id=".$ey['karyawan_id']." 
			AND a.periode_id=".$last_periode_id." 
			AND b.tipe<3 ";
		$result1 = my_query($query);	
		$komponen_gajis = my_fetch_array($result1);
		if(	$komponen_gajis ){
			$gaji_bl+=($komponen_gajis['kalkulasi']);
			
		}
		$detailproperty = array(
			'href'=>'index.php?com=pr_validasi&task=detail&karyawan_id='.$ey['karyawan_id'],
			'title'=>'Detail Gaji'
		);
		$detail_button = button_icon( 'b_props.png' , $detailproperty  );

		$detailabsenproperty = array(
			'href'=>'index.php?com=pr_validasi&task=detail_absen&karyawan_id='.$ey['karyawan_id'],
			'title'=>'Detail Absen'
		);
		$detail_absen_button = button_icon( 'b_dbstatistics.png' , $detailabsenproperty  );

		$detailpremiproperty = array(
			'href'=>'index.php?com=pr_validasi&task=detail_premi&karyawan_id='.$ey['karyawan_id'],
			'title'=>'Detail Premi Kesehatan'
		);
		$detail_premi_button = button_icon( 'b_dbstatistics.png' , $detailpremiproperty  );

		$row[] = array(
			'nik'=>position_text_align ($karyawan['nik'] ,'center'),    
			'gd'=>  $karyawan['nama'] ,  
			'gaji_bi'=>  position_text_align (rp_format($gaji_bi ) ,'right'),      
			'gaji_bl'=>  position_text_align (rp_format($gaji_bl ) ,'right'),     
			'selisih'=>   position_text_align (rp_format($gaji_bi -$gaji_bl ) ,'right'),    
			'operasi'=> position_text_align( $detail_button.' '.$detail_absen_button.' '.$detail_premi_button, 'right'),
		); 
	}
	$datas = table_rows($row);
	$paging = $kgPagerOBJ ->showPaging();	
	$view  = form_header( "..." , "..."  );
	$view .= form_field_display( '<span class="label_form"> '.get_tanggal_by_periode_id().'</span>'   , "<b>Periode Gaji</b>"    ); 
$view  = form_footer(   );
	$menuontop = array(  
		'Komponen Gaji' => array('onclick'=>'javascript:location.href=\'index.php?com=pr_validasi&task=list_komponen\''),
		'Hasil Pajak' => array('onclick'=>'javascript:location.href=\'index.php?com=pr_validasi_pajak\''),
		);
	$search = '<form method="GET"><input type="hidden" name="com" value="'.$_GET['com'].'" /><span style="font:10px verdana">
	<b>Pencarian cepat</b></span><br/><input type="text"  style="width:200px;" name="key" value="'.(isset($_GET['key']) ? $_GET['key']: "").'" />
	<input class="simple_search" type="submit" value=" CARI " /> </form>';
	$printmenu = additional_menu_on_list( $menuontop ,$search ); 
	return  $view.$printmenu.table_builder($header , $datas ,  6 , false , $paging  );
}

function get_nominal_rapel($komponen_id , $karyawan_id, $prev_periode_id){
	
	$query = "SELECT  nominal  
		FROM pr_rapel_komponen_karyawan  
		WHERE  karyawan_id = {$karyawan_id} AND periode_prev_id = {$prev_periode_id} AND  komponen_id = {$komponen_id} ";
	$result = my_query($query);
	$row = my_fetch_array($result);
	return $row['nominal'];
	 
}

function list_validasi_detail($karyawan_id){
	$karyawan = loaddata_karyawan($ey['karyawan_id']);
	$jabatan = my_get_data_by_id('jabatan' ,'jabatan_id' , ($karyawan['jabatan_id']<>'' ? $karyawan['jabatan_id'] : 0 ));

	$query = " SELECT gaji_dibayar FROM pr_gaji 
		WHERE periode_id=0
		AND karyawan_id=".$karyawan_id
	;
	$result = my_query($query);	
	$gajis = my_fetch_array($result);	
	$nilai_bi= $gajis['gaji_dibayar'] ;
	
	$periode_id=get_periode_gaji() ;
	$last_periode_id=get_last_periode_id($periode_id) ;
	$query = " SELECT gaji_dibayar FROM pr_gaji 
		WHERE periode_id=".($last_periode_id)."
		AND karyawan_id=".$karyawan_id
	;
	$result = my_query($query);	
	$gajis = my_fetch_array($result);	
	$nilai_bl= $gajis['gaji_dibayar'] ;

	$tipes = array(
		'1'=>'Tunjangan',
		'2'=>'Potongan',
		'3'=>'Iuran',
	);		
	$header = array(
		'#'=>array('style'=>'text-align:center;border-bottom:2px solid;width:5%'),  
		'Nama Komponen'=>array('style'=>'text-align:left;border-bottom:2px solid;width:30%'),  
		'Tipe'=>array('style'=>'text-align:left;border-bottom:2px solid;width:5%'),  
		'Bulan Ini'=>array('style'=>'text-align:right;border-bottom:2px solid;width:20%'),  
		'Bulan Lalu'=>array('style'=>'text-align:right;border-bottom:2px solid;width:15%'),  
		'Selisih'=>array('style'=>'text-align:right;border-bottom:2px solid;width:20%'),  
	);
	$i=1;
	$total_bi=$tot_bi=$nilai_bi;
	$total_bl=$tot_bl=$nilai_bl;
	$row = array();
	$row[] = array(
		'e'=>position_text_align($i,'center'),
		'nama'=>'Gaji Dibayarkan' ,
		'tipe'=>' ',
		'bi'=> position_text_align(rp_format($nilai_bi), 'right' ),
		'bl'=> position_text_align(rp_format($nilai_bl), 'right' ),
		'sel'=> position_text_align(rp_format($nilai_bi-$nilai_bl), 'right' ),
	);	
	$rapel_komponen_gaji = get_nominal_rapel(0 , $karyawan_id, $last_periode_id); 
	
	if((int) $rapel_komponen_gaji <> 0){
		$i++;
		$row[] = array(
			'e'=>position_text_align($i ,'center'),
			'nama'=>'<b>Rapel </b> gaji di bayarkan' ,
			'tipe'=>$tipes[$ey['tipe']],
			'bi'=> position_text_align(rp_format($rapel_komponen_gaji), 'right' ),
			'bl'=> position_text_align(rp_format(0), 'right' ),
			'sel'=> position_text_align(rp_format($rapel_komponen_gaji ), 'right' ),
		);
		$tot_bi+=$rapel_komponen_gaji;
		$total_bi+=$rapel_komponen_gaji;
	}
	$tipe=1;
	$query = "SELECT a.komponen_id,b.nama_komponen_gaji,b.tipe  
			FROM pr_gaji_komponen a 
			INNER JOIN pr_komponen_gaji b ON a.komponen_id=b.komponen_gaji_id
			WHERE a.karyawan_id={$karyawan_id} AND 
			(a.periode_id =0 OR a.periode_id={$last_periode_id} ) 
			GROUP BY a.komponen_id
			ORDER BY b.tipe,a.komponen_id"
	;
	$result = my_query($query);
	while($ey = my_fetch_array($result)){
		if((int) $ey['tipe']<>$tipe){
			$row[] = array(
				'e'=>' ',
				'nama'=>'Total '.$tipes[$tipe] ,
				'tipe'=>' ',
				'bi'=> position_text_align(rp_format($total_bi), 'right' ),
				'bl'=> position_text_align(rp_format($total_bl), 'right' ),
				'sel'=> position_text_align(rp_format($total_bi-$total_bl), 'right' ),
			);	
			$total_bi=$total_bl=0;
			$tipe=$ey['tipe'];
		}
		
		$i++;
	
		
		$komponen_id=$ey['komponen_id'] ;

		$query = "SELECT kalkulasi  
			FROM pr_gaji_komponen 
			WHERE periode_id=0 
			AND karyawan_id=".$karyawan_id." 
			AND komponen_id=".$komponen_id
		;
		$result1 = my_query($query);
		$ey0 = my_fetch_array($result1);		
		$nilai_bi= $ey0['kalkulasi'] ;
		
		$query = "SELECT kalkulasi  
			FROM pr_gaji_komponen 
			WHERE periode_id=".($last_periode_id)." 
			AND karyawan_id=".$karyawan_id." 
			AND komponen_id=".$komponen_id
		;
		$result1 = my_query($query);
		$ey1 = my_fetch_array($result1);
		
		$nilai_bl= $ey1['kalkulasi'] ;
		if($nilai_bi<>0 OR $nilai_bl<>0){
			$row[] = array(
				'e'=>position_text_align($i,'center'),
				'nama'=>$ey['nama_komponen_gaji'] ,
				'tipe'=>$tipes[$ey['tipe']],
				'bi'=> position_text_align(rp_format($nilai_bi) , 'right' ),
				'bl'=> position_text_align(rp_format(  $nilai_bl   ), 'right' ),
				'sel'=> position_text_align(rp_format($nilai_bi-$nilai_bl), 'right' ),
			);
		}
		
		$rapel_komponen = get_nominal_rapel($komponen_id , $karyawan_id, $last_periode_id);
		$rapel_komponen = $ey['tipe'] <> '2' ? $rapel_komponen : $rapel_komponen * -1;
		if((int) $rapel_komponen <> 0){
			$i++;
			$row[] = array(
				'e'=>position_text_align($i,'center'),
				'nama'=>'<b>Rapel </b> '.$ey['nama_komponen_gaji'] ,
				'tipe'=>$tipes[$ey['tipe']],
				'bi'=> position_text_align(rp_format(  $rapel_komponen ) , 'right' ),
				'bl'=> position_text_align(rp_format(0), 'right' ),
				'sel'=> position_text_align(rp_format($rapel_komponen ), 'right' ),
			);
		}
		
		if( (int) $ey['tipe'] <3){
			$tot_bi+=$nilai_bi; 
			$tot_bi+=$rapel_komponen;
			$tot_bl+=$nilai_bl;
		}	
		$total_bi+=$nilai_bi;
			$total_bi+=$rapel_komponen;
		$total_bl+=$nilai_bl;		
	}
	
	$row[] = array(
		'e'=>' ',
		'nama'=>'Take Home Pay' ,
		'tipe'=>' ',
		'bi'=> position_text_align(rp_format($tot_bi), 'right' ),
		'bl'=> position_text_align(rp_format($tot_bl), 'right' ),
		'sel'=> position_text_align(rp_format($tot_bi-$tot_bl), 'right' ),
	);
	
	$datas = table_rows($row);

	$karyawan = loaddata_karyawan($karyawan_id);
	$pro =   karyawan_header_detail($karyawan  );
	$view ='<table width="90%" cellspacing="0" cellpadding="4"><tr>'; 
	$view .= form_header( "..." , "..."  );
	$view .= '<tr><td><td><div style="width:100%;text-align:right;">
	<!-- input type="button" value="Cetak Slip Gaji" class="main_button" onclick="javascript:window.open(\'index.php?com=report&task=slip_gaji&id='.$karyawan_id.'\',\'mywin\',\'left=20,top=20,width=800,height=600,toolbar=0,resizable=0\');"/--> 	
	<input type="button" value="Back" class="main_button" onclick="javascript:location.href=\'index.php?com=pr_validasi\'"/></div></td></tr>'   ; 
	return  $pro.$view. table_builder($header , $datas ,  3 , false );
} 

function get_tanggal_by_periode_id(){
	$periode_id =get_periode_gaji();
	$periodes = my_get_data_by_id('pr_periode','periode_id',$periode_id);
	$bulan = (int) date('m' , strtotime($periodes['tanggal']));
	$tahun = $periodes['tahun'] ;
	return sprintf( '%02d',$bulan).'-'.$tahun ;
}

function list_komponen_export_excel(){ 
	$periode_id=get_periode_gaji() ;
	$last_periode_id=get_last_periode_id($periode_id) ;
	
	$tipes = array(
		'1'=>'Tunjangan',
		'2'=>'Potongan',
		'3'=>'Iuran',
	);	

	$header = array(
		'#'=>array('style'=>'text-align:center;border-bottom:2px solid;width:5%'),  
		'Nama Komponen'=>array('style'=>'text-align:left;border-bottom:2px solid;width:30%'),  
		'Tipe'=>array('style'=>'text-align:left;border-bottom:2px solid;width:5%'),  
		'Bulan Ini'=>array('style'=>'text-align:right;border-bottom:2px solid;width:20%'),  
		'Bulan Lalu'=>array('style'=>'text-align:right;border-bottom:2px solid;width:20%'),  
		'Selisih'=>array('style'=>'text-align:right;border-bottom:2px solid;width:15%'),   
	);

	$query = "SELECT komponen_gaji_id, nama_komponen_gaji, tipe 
			FROM pr_komponen_gaji
			ORDER BY tipe, komponen_gaji_id"
	;
	
	$result = my_query($query);
	
	$query1 = " SELECT sum(gaji_dibayar) as gaji_dibayar  FROM pr_gaji 
		WHERE periode_id=0"
	;
	$result1 = my_query($query1);	
	$gajis = my_fetch_array($result1);	
	$bulan_ini= $gajis['gaji_dibayar'] ;
	 
	$query1 = " SELECT SUM(gaji_dibayar) as gaji_dibayar FROM pr_gaji 
		WHERE periode_id=".($last_periode_id)
	;
	$result1 = my_query($query1);	
	$gajis = my_fetch_array($result1);	
	$bulan_lalu= $gajis['gaji_dibayar'] ;
	if($i==0 AND ($bulan_ini<>0 OR $bulan_lalu<>0)){
		$i++;
		$detailproperty = array(
			'href'=>'index.php?com=pr_validasi&task=list_komponen_detail&komponen_id=1000',
			'title'=>'Detail'
		);
		$detail_button = button_icon( 'b_props.png' , $detailproperty  );
		$row[] = array(
			'no'=> $i, 
			'gd'=>  'Gaji dibayarkan' ,
			'tipe'=>'Cash',
			'bulan_ini'=>   ($bulan_ini)       ,
			'bulan_lalu'=>   ($bulan_lalu)     ,
			'selisih'=>  ($bulan_ini-$bulan_lalu ) 
		); 
	}	
	
	while($ey = my_fetch_array($result)){
		$komponen_id=$ey['komponen_gaji_id'];
		$query = "SELECT SUM(kalkulasi) as kalkulasi 
			FROM pr_gaji_komponen  
			WHERE komponen_id={$komponen_id}
			AND periode_id=0" ;
		$res = my_fetch_array(my_query($query));
		$bulan_ini=$res['kalkulasi'];

		$query = "SELECT SUM(kalkulasi) as kalkulasi 
			FROM pr_gaji_komponen  
			WHERE komponen_id={$komponen_id}
			AND periode_id={$last_periode_id}" ;
		$res = my_fetch_array(my_query($query));
		$bulan_lalu=$res['kalkulasi'];	
	
		$detailproperty = array(
			'href'=>'index.php?com=pr_validasi&task=list_komponen_detail&komponen_id='.$ey['komponen_gaji_id'],
			'title'=>'Detail'
		);
		$detail_button = button_icon( 'b_props.png' , $detailproperty  );
		//if($bulan_ini<>0 OR $bulan_lalu<>0){ //TAMPILKAN YANG BUKAN 0
			$i++;
			$row[] = array(
				'no'=> $i, 
				'gd'=>  $ey['nama_komponen_gaji'] ,
				'tipe'=>$tipes[$ey['tipe']],
				'bulan_ini'=>   ($bulan_ini) ,     
				'bulan_lalu'=>   ($bulan_lalu) ,      
				'selisih'=>   ($bulan_ini-$bulan_lalu )     
			); 
		//}									//TAMPILKAN YANG BUKAN 0
	}

	//hitung takehomepay
	$query1 = " SELECT sum(takehomepay) as takehomepay  FROM pr_gaji 
		WHERE periode_id=0"
	;
	$result1 = my_query($query1);	
	$gajis = my_fetch_array($result1);	
	$bulan_ini= $gajis['takehomepay'] ;
	 
	$query1 = " SELECT SUM(takehomepay) as takehomepay FROM pr_gaji 
		WHERE periode_id=".($last_periode_id)
	;
	$result1 = my_query($query1);	
	$gajis = my_fetch_array($result1);	
	$bulan_lalu= $gajis['takehomepay'] ;
	if($bulan_ini<>0 OR $bulan_lalu<>0){
		$i++;
		$detailproperty = array(
			'href'=>'index.php?com=pr_validasi&task=list_komponen_detail&komponen_id=0',
			'title'=>'Detail'
		);
		$detail_button = button_icon( 'b_props.png' , $detailproperty  );
		$row[] = array(
			'no'=>position_text_align($i,'center'),  
			'gd'=>  'Take Homepay' ,
			'tipe'=>'Cash ',
			'bulan_ini'=>    $bulan_ini ,      
			'bulan_lalu'=>   $bulan_lalu ,     
			'selisih'=>    ($bulan_ini-$bulan_lalu ) ,  
			 
		); 
	}	
	$datas = table_rows_excel($row); 
	return table_builder_excel($header , $datas , 6 ,false );  
}

function list_komponen(){
	$periode_id=get_periode_gaji() ;
	$last_periode_id=get_last_periode_id($periode_id) ;
	$tipes = array(
		'1'=>'Tunjangan',
		'2'=>'Potongan',
		'3'=>'Iuran',
	);	

	$header = array(
		'#'=>array('style'=>'text-align:center;border-bottom:2px solid;width:5%'),  
		'Nama Komponen'=>array('style'=>'text-align:left;border-bottom:2px solid;width:30%'),  
		'Tipe'=>array('style'=>'text-align:left;border-bottom:2px solid;width:5%'),  
		'Bulan Ini'=>array('style'=>'text-align:right;border-bottom:2px solid;width:20%'),  
		'Bulan Lalu'=>array('style'=>'text-align:right;border-bottom:2px solid;width:20%'),  
		'Selisih'=>array('style'=>'text-align:right;border-bottom:2px solid;width:15%'),  
		' '=>array('style'=>'border-bottom:2px solid;width:5%'), 
	);

	$query = "SELECT komponen_gaji_id, nama_komponen_gaji, tipe 
			FROM pr_komponen_gaji
			ORDER BY tipe,  komponen_gaji_id "
	;
	
	$result = my_query($query);
 
	//hitung gaji dibayarkan
	$query1 = " SELECT sum(gaji_dibayar) as gaji_dibayar  FROM pr_gaji 
		WHERE periode_id=0"
	;
	$result1 = my_query($query1);	
	$gajis = my_fetch_array($result1);	
	$bulan_ini= $gajis['gaji_dibayar'] ;
	  
	$query1 = " SELECT SUM(gaji_dibayar) as gaji_dibayar FROM pr_gaji 
		WHERE periode_id=".($last_periode_id)
	;
	$result1 = my_query($query1);	
	$gajis = my_fetch_array($result1);	
	$bulan_lalu= $gajis['gaji_dibayar'] ;
	if($i==0 AND ($bulan_ini<>0 OR $bulan_lalu<>0)){
		$i++;
		$detailproperty = array(
			'href'=>'index.php?com=pr_validasi&task=list_komponen_detail&komponen_id=1000',
			'title'=>'Detail'
		);
		$detail_button = button_icon( 'b_props.png' , $detailproperty  );
		$row[] = array(
			'no'=>position_text_align($i,'center'),  
			'gd'=>  'Gaji dibayarkan' ,
			'tipe'=>'Cash',
			'bulan_ini'=>  position_text_align (rp_format($bulan_ini) ,'right'),      
			'bulan_lalu'=>  position_text_align (rp_format($bulan_lalu) ,'right'),     
			'selisih'=>   position_text_align (rp_format($bulan_ini-$bulan_lalu ) ,'right'),    
			'operasi'=> position_text_align( $detail_button, 'right'),
		); 
	}	
		
	while($ey = my_fetch_array($result)){
		$komponen_id=$ey['komponen_gaji_id'];
		$query = "SELECT SUM(kalkulasi) as kalkulasi 
			FROM pr_gaji_komponen  
			WHERE komponen_id={$komponen_id}
			AND periode_id=0" ;
		$res = my_fetch_array(my_query($query));
		$bulan_ini=$res['kalkulasi'];

		$query = "SELECT SUM(kalkulasi) as kalkulasi 
			FROM pr_gaji_komponen  
			WHERE komponen_id={$komponen_id}
			AND periode_id={$last_periode_id}" ;
		$res = my_fetch_array(my_query($query));
		$bulan_lalu=$res['kalkulasi'];	
	
		$detailproperty = array(
			'href'=>'index.php?com=pr_validasi&task=list_komponen_detail&komponen_id='.$ey['komponen_gaji_id'],
			'title'=>'Detail'
		);
		$detail_button = button_icon( 'b_props.png' , $detailproperty  );
		//if($bulan_ini<>0 OR $bulan_lalu<>0){ //TAMPILKAN YANG BUKAN 0
			$i++;
			$row[] = array(
				'no'=>position_text_align($i,'center'),  
				'gd'=>  strtoupper($ey['nama_komponen_gaji']) ,
				'tipe'=>$tipes[$ey['tipe']],
				'bulan_ini'=>  position_text_align (rp_format($bulan_ini) ,'right'),      
				'bulan_lalu'=>  position_text_align (rp_format($bulan_lalu) ,'right'),     
				'selisih'=>   position_text_align (rp_format($bulan_ini-$bulan_lalu ) ,'right'),    
				'operasi'=> position_text_align( $detail_button, 'right'),
			); 
		//}									//TAMPILKAN YANG BUKAN 0
	}

	//hitung takehomepay
	$query12 = " SELECT sum(takehomepay) as takehomepay  FROM pr_gaji 
		WHERE periode_id=0"
	;
	$result12 = my_query($query12);	
	$gajis2 = my_fetch_array($result12);	
	$bulan_ini= $gajis2['takehomepay'] ;
 	$query1 = " SELECT SUM(takehomepay) as takehomepay FROM pr_gaji 
		WHERE periode_id=".($last_periode_id)
	;
	$result1 = my_query($query1);	
	$gajis = my_fetch_array($result1);	
	$bulan_lalu= $gajis['takehomepay'] ;
	if($bulan_ini<>0 OR $bulan_lalu<>0){
		$i++;
		$detailproperty = array(
			'href'=>'index.php?com=pr_validasi&task=list_komponen_detail&komponen_id=0',
			'title'=>'Detail'
		);
		$detail_button = button_icon( 'b_props.png' , $detailproperty  );
		$row[] = array(
			'no'=>position_text_align($i,'center'),  
			'gd'=>  'Take Homepay' ,
			'tipe'=>'Cash ',
			'bulan_ini'=>  position_text_align (rp_format($bulan_ini) ,'right'),      
			'bulan_lalu'=>  position_text_align (rp_format($bulan_lalu) ,'right'),     
			'selisih'=>   position_text_align (rp_format($bulan_ini-$bulan_lalu ) ,'right'),    
			'operasi'=> position_text_align( $detail_button, 'right'),
		); 
	}	
	
	$datas = table_rows($row);
	//$paging = $kgPagerOBJ ->showPaging();	
	$view  = form_header( "..." , "..."  );
	$view .= form_field_display( '<span class="label_form"> '.get_tanggal_by_periode_id().'</span>'   , "<b>Periode Gaji</b>"    ); 
	$menuontop = array(  
		'per Karyawan' => array('onclick'=>'javascript:location.href=\'index.php?com=pr_validasi&task=list_karyawan\''),
		'Excel Komponen' => array('onclick'=>'javascript:location.href=\'index.php?com=pr_validasi&task=list_komponen_excel\''),
		);
	$printmenu = additional_menu_on_list( $menuontop , '');
	return  $view.$printmenu.table_builder($header , $datas ,  6 , false /*, $paging */  );
}

function list_komponen_detail_excel($komponen_id){
	$header = array(
		'NIK'=>array('style'=>'text-align:center;border-bottom:2px solid;width:10%'),  
		'Nama'=>array('style'=>'text-align:left;border-bottom:2px solid;width:60%'),  
		'Nominal'=>array('style'=>'text-align:right;border-bottom:2px solid;width:30%'),  
	);
	$query = "SELECT karyawan_id,kalkulasi 
		FROM pr_gaji_komponen 
		WHERE periode_id=0 
		AND komponen_id={$komponen_id} 
		ORDER BY karyawan_id"
	;  
	$result = my_query($query);
	$row = array();
	while($ey = my_fetch_array($result)){
		$karyawan_temp=$ey['karyawan_id'];
		$karyawan = loaddata_karyawan($ey['karyawan_id']);
		$row[] = array(
			'nik'=>'\''.sprintf('%07d' ,$karyawan['nik']  ),    
			'gd'=>  $karyawan['nama_gelar'] ,  
			'nominal'=>   round($ey['kalkulasi']),      
		); 
	}
	
	$datas = table_rows_excel($row); 
	return table_builder_excel($header , $datas , 6 ,false ); 
}

function list_komponen_gaji_excel(){
	$header = array(
		'NIK'=>array('style'=>'text-align:center;border-bottom:2px solid;width:10%'),  
		'Nama'=>array('style'=>'text-align:left;border-bottom:2px solid;width:60%'),  
		'Nominal'=>array('style'=>'text-align:right;border-bottom:2px solid;width:30%'),  
	);
	$query = "
		SELECT a.karyawan_id, a.nik ,b.nama  FROM karyawan a 
		INNER JOIN biodata b ON a.biodata_id = b.biodata_id
		WHERE a.karyawan_id NOT IN (select karyawan_id FROM karyawan_disable)
		AND a.karyawan_id NOT IN (select karyawan_id FROM pemberhentian) 		
	";
	$result = my_query($query);
	$row = array();
	while($ey = my_fetch_array($result)){		
		$nominal = total_gaji_dibayarkan($ey['karyawan_id']);  
		$row[] = array(
			'nik'=>'\''.sprintf('%07d' ,$ey['nik']  ),    
			'gd'=>   $ey['nama'] ,    
			'nominal'=>   round($ey['karyawan_id']),   
		); 
	}
	
	$datas = table_rows_excel($row); 
	return table_builder_excel($header , $datas , 6 ,false ); 
}


function list_komponen_thp_excel(){
	$header = array(
		'NIK'=>array('style'=>'text-align:center;border-bottom:2px solid;width:10%'),  
		'Nama'=>array('style'=>'text-align:left;border-bottom:2px solid;width:60%'),  
		'Nominal'=>array('style'=>'text-align:right;border-bottom:2px solid;width:30%'),  
	);
	$query = "
		SELECT a.karyawan_id, a.nik ,b.nama  FROM karyawan a 
		INNER JOIN biodata b ON a.biodata_id = b.biodata_id
		WHERE a.karyawan_id NOT IN (select karyawan_id FROM karyawan_disable)
		AND a.karyawan_id NOT IN (select karyawan_id FROM pemberhentian) 		
	";
	$result = my_query($query);
	$row = array();
	while($ey = my_fetch_array($result)){  
		$nominal = total_thp_periode($ey['karyawan_id']);
		$row[] = array(
			'nik'=>'\''.sprintf('%07d', $ey['nik']  ),    
			'gd'=>  $ey['nama'] ,  
			'nominal'=>   round($nominal),   
		);    
	}
	
	$datas = table_rows_excel($row); 
	return table_builder_excel($header , $datas , 6 ,false ); 
}


function list_komponen_gaji(){
	$header = array(
		'NIK'=>array('style'=>'text-align:center;border-bottom:2px solid;width:10%'),  
		'Nama'=>array('style'=>'text-align:left;border-bottom:2px solid;width:60%'),  
		'Nominal'=>array('style'=>'text-align:right;border-bottom:2px solid;width:30%'),  
	);
	
	$query = "
		SELECT a.karyawan_id, a.nik ,b.nama  FROM karyawan a 
		INNER JOIN biodata b ON a.biodata_id = b.biodata_id
		WHERE a.karyawan_id NOT IN (select karyawan_id FROM karyawan_disable)
		AND a.karyawan_id NOT IN (select karyawan_id FROM pemberhentian) 		
	";
	$result = my_query($query );
	$total_records = my_num_rows($result );
	$scroll_page =5;  
	$per_page =25;  
	$current_page = isset($_GET['page']) ? (int) $_GET['page'] : 1 ; 
	if($current_page < 1){
		$current_page = 1;
	}		 
	$pager_url  ="index.php?com={$_GET['com']}&task={$_GET['task']}&komponen_id={$_GET['komponen_id']}&field={$_GET['field']}&key={$_GET['key']}&page=";	 
	$inactive_page_tag = 'style="padding:4px;background-color:#BBBBBB"';  
	$previous_page_text = ' Mundur '; 
	$next_page_text = ' Maju ';  
	$first_page_text = ' Awal '; 
	$last_page_text = ' Akhir ';
	
	$kgPagerOBJ = new kgPager();
	$kgPagerOBJ->pager_set(
		$pager_url, 
		$total_records, 
		$scroll_page, 
		$per_page, 
		$current_page, 
		$inactive_page_tag, 
		$previous_page_text, 
		$next_page_text, 
		$first_page_text, 
		$last_page_text ,$pager_url_last); 
	 		
	$result = my_query($query ." LIMIT ".$kgPagerOBJ->start.", ".$kgPagerOBJ->per_page); 	
	$row = array(); 
	$i = ($current_page  - 1 ) * 25; 
	while($ey = my_fetch_array($result )){ 
		$row[] = array(
			'nik'=>position_text_align ($ey['nik'] ,'center'),    
			'gd'=>  $ey['nama'] ,  
			'nominal'=>  position_text_align (rp_format( total_gaji_dibayarkan($ey['karyawan_id'])) ,'right'),      
		); 
	}
	$datas = table_rows($row); 
	$paging = $kgPagerOBJ ->showPaging();
	$view  = form_header( "..." , "..."  );
	$view .= form_field_display( '<span class="label_form"> '.get_tanggal_by_periode_id().'</span>'   , "<b>Periode Gaji</b>"    ); 
	$view .= form_field_display( '<span class="label_form"> Gaji dibayarkan</span>'   , "<b>Komponen</b>"    ); 
	$menuontop = array(  
	//	'Cetak' => array('onclick'=>'javascript:window.open(\'index.php?com=report&task=rpt_rinci_komponen&komponen_id=0\',\'mywin\',\'left=20,top=20,width=800,height=600,toolbar=0,resizable=0\');'),
		'Excel' => array('onclick'=>'javascript:location.href=\'index.php?com=pr_validasi&task=list_komponen_gaji_excel\''),
		'Back' => array('onclick'=>'javascript:location.href=\'index.php?com=pr_validasi&task=list_komponen\''),
	);
	$printmenu = additional_menu_on_list( $menuontop , '');
	return $view . $printmenu . table_builder($header , $datas ,  3 ,false , $paging  );
}

function total_gaji_dibayarkan($karyawan_id){
	$query = "SELECT gaji_dibayar  FROM pr_gaji 
	WHERE periode_id = 0 AND
	karyawan_id = {$karyawan_id}";
	$result = my_query($query);
	$row = my_fetch_array($result);
	return $row['gaji_dibayar'];
}
function list_komponen_thp(){
	$header = array(
		'NIK'=>array('style'=>'text-align:center;border-bottom:2px solid;width:10%'),  
		'Nama'=>array('style'=>'text-align:left;border-bottom:2px solid;width:60%'),  
		'Nominal'=>array('style'=>'text-align:right;border-bottom:2px solid;width:30%'),  
	);
	
	$query = "
		SELECT a.karyawan_id, a.nik ,b.nama  FROM karyawan a 
		INNER JOIN biodata b ON a.biodata_id = b.biodata_id
		WHERE a.karyawan_id NOT IN (select karyawan_id FROM karyawan_disable)
		AND a.karyawan_id NOT IN (select karyawan_id FROM pemberhentian) 		
	";
	$result = my_query($query );
	$total_records = my_num_rows($result );
	$scroll_page =5;  
	$per_page =25;  
	$current_page = isset($_GET['page']) ? (int) $_GET['page'] : 1 ; 
	if($current_page < 1){
		$current_page = 1;
	}		 
	$pager_url  ="index.php?com={$_GET['com']}&task={$_GET['task']}&komponen_id={$_GET['komponen_id']}&field={$_GET['field']}&key={$_GET['key']}&page=";	 
	$inactive_page_tag = 'style="padding:4px;background-color:#BBBBBB"';  
	$previous_page_text = ' Mundur '; 
	$next_page_text = ' Maju ';  
	$first_page_text = ' Awal '; 
	$last_page_text = ' Akhir ';
	
	$kgPagerOBJ = new kgPager();
	$kgPagerOBJ->pager_set(
		$pager_url, 
		$total_records, 
		$scroll_page, 
		$per_page, 
		$current_page, 
		$inactive_page_tag, 
		$previous_page_text, 
		$next_page_text, 
		$first_page_text, 
		$last_page_text ,$pager_url_last); 
	 		
	$result = my_query($query ." LIMIT ".$kgPagerOBJ->start.", ".$kgPagerOBJ->per_page); 	
	$row = array(); 
	$i = ($current_page  - 1 ) * 25; 
	while($ey = my_fetch_array($result )){ 
		$row[] = array(
			'nik'=>position_text_align ($ey['nik'] ,'center'),    
			'gd'=>  $ey['nama'] ,  
			'nominal'=>  position_text_align (rp_format( total_thp_periode($ey['karyawan_id'])) ,'right'),      
		); 
	}
	$datas = table_rows($row); 
	$paging = $kgPagerOBJ ->showPaging();
	$view  = form_header( "..." , "..."  );
	$view .= form_field_display( '<span class="label_form"> '.get_tanggal_by_periode_id().'</span>'   , "<b>Periode Gaji</b>"    ); 
	$view .= form_field_display( '<span class="label_form"> Take home pay</span>'   , "<b>Komponen</b>"    ); 
	$menuontop = array(  
	//	'Cetak' => array('onclick'=>'javascript:window.open(\'index.php?com=report&task=rpt_rinci_komponen&komponen_id=0\',\'mywin\',\'left=20,top=20,width=800,height=600,toolbar=0,resizable=0\');'),
		'Excel' => array('onclick'=>'javascript:location.href=\'index.php?com=pr_validasi&task=list_komponen_thp_excel\''),
		'Back' => array('onclick'=>'javascript:location.href=\'index.php?com=pr_validasi&task=list_komponen\''),
	);
	$printmenu = additional_menu_on_list( $menuontop , '');
	return $view . $printmenu . table_builder($header , $datas ,  3 ,false , $paging  );
}

function total_thp_periode($karyawan_id){
 
	 
	$query = "SELECT takehomepay  FROM pr_gaji 
	WHERE periode_id = 0 AND
	karyawan_id = {$karyawan_id}";
	
	$result = my_query($query);
	$row = my_fetch_array($result);
	return $row['takehomepay']  ;
}


function list_komponen_detail($komponen_id){
	$komponens=my_get_data_by_id('pr_komponen_gaji','komponen_gaji_id',$komponen_id);
	$header = array(
		'NIK'=>array('style'=>'text-align:center;border-bottom:2px solid;width:10%'),  
		'Nama'=>array('style'=>'text-align:left;border-bottom:2px solid;width:60%'),  
		'Nominal'=>array('style'=>'text-align:right;border-bottom:2px solid;width:30%'),  
	);
	$query = "SELECT karyawan_id,kalkulasi 
		FROM pr_gaji_komponen 
		WHERE periode_id=0 
		AND komponen_id={$komponen_id} 
		ORDER BY karyawan_id"
	; 
	$result = my_query($query);
	$total_records = my_num_rows($result );
	$scroll_page =5;  
	$per_page =25;  
	$current_page = isset($_GET['page']) ? (int) $_GET['page'] : 1 ; 
	if($current_page < 1){
		$current_page = 1;
	}		 
	$pager_url  ="index.php?com={$_GET['com']}&task={$_GET['task']}&field={$_GET['field']}
	&komponen_id={$_GET['komponen_id']}&page=";	 
	$inactive_page_tag = 'style="padding:4px;background-color:#BBBBBB"';  
	$previous_page_text = ' Mundur '; 
	$next_page_text = ' Maju ';  
	$first_page_text = ' Awal '; 
	$last_page_text = ' Akhir ';
	
	$kgPagerOBJ = new kgPager();
	$kgPagerOBJ->pager_set(
		$pager_url, 
		$total_records, 
		$scroll_page, 
		$per_page, 
		$current_page, 
		$inactive_page_tag, 
		$previous_page_text, 
		$next_page_text, 
		$first_page_text, 
		$last_page_text ,$pager_url_last); 
				
	$result = my_query($query ." LIMIT ".$kgPagerOBJ->start.", ".$kgPagerOBJ->per_page); 	
	$row = array(); 
	$i = ($current_page  - 1 ) * 25; 
	while($ey = my_fetch_array($result)){
		$karyawan_temp=$ey['karyawan_id'];
		$karyawan = loaddata_karyawan($ey['karyawan_id']);
		$row[] = array(
			'nik'=>position_text_align ($karyawan['nik'] ,'center'),    
			'gd'=>  $karyawan['nama_gelar'] ,  
			'nominal'=>  position_text_align (rp_format($ey['kalkulasi']) ,'right'),      
		); 
	}
	$datas = table_rows($row);
	$paging = $kgPagerOBJ ->showPaging();	
	$view  = form_header( "..." , "..."  );
	$view .= form_field_display( '<span class="label_form"> '.get_tanggal_by_periode_id().'</span>'   , "<b>Periode Gaji</b>"    ); 
	$view .= form_field_display( '<span class="label_form"> '.$komponens['nama_komponen_gaji'].'</span>'   , "<b>Komponen</b>"    ); 
	$menuontop = array(  
	//	'Cetak' => array('onclick'=>'javascript:window.open(\'index.php?com=report&task=rpt_rinci_komponen&komponen_id='.$komponen_id.'\',\'mywin\',\'left=20,top=20,width=800,height=600,toolbar=0,resizable=0\');'),
		'Excel' => array('onclick'=>'javascript:location.href=\'index.php?com=pr_validasi&task=list_komponen_detail_excel&komponen_id='.$komponen_id.'\''),
		'Back' => array('onclick'=>'javascript:location.href=\'index.php?com=pr_validasi&task=list_komponen\''),
	);
	$printmenu = additional_menu_on_list( $menuontop , '');
	return  $view.$printmenu.table_builder($header , $datas ,  6 , false , $paging  );
}

function list_detail_absen($karyawan_id){
	$periode_id=get_periode_gaji() ;
	$periode = my_get_data_by_id('pr_periode','periode_id',$periode_id);
	$month = date('m',strtotime($periode['tanggal']));
	$year = date('Y',strtotime($periode['tanggal']));
	$periode_ini=$month.'/'.$year ;
	if($month==1){
		$month=12;
		$year--;
	}else{
		$month--;
	}	
	$periode_lalu=$month.'/'.$year ;
	$tgl_akhir=date('d', strtotime(get_last_date_by_month($year,$month))) ;
	
	
	$header = array(
		'#'=>array('style'=>'text-align:center;border-bottom:2px solid;width:5%'),  
		'Keterangan'=>array('style'=>'text-align:left;border-bottom:2px solid;width:40%'),  
		'Periode'=>array('style'=>'text-align:left;border-bottom:2px solid;width:20%'),  
		'Nilai'=>array('style'=>'text-align:right;border-bottom:2px solid;width:20%'),  
		'Satuan'=>array('style'=>'text-align:left;border-bottom:2px solid;width:15%'),  
		' '=>array('style'=>'border-bottom:2px solid;width:5%'), 
	);
	$i=0;
	$row= array();
	$query = "SELECT * FROM a_absen_payroll 
		WHERE periode_id={$periode_id}
		AND karyawan_id={$karyawan_id}"
	;
	$result = my_query($query);	
	$data_absens = my_fetch_array($result);

	$i++;
	$detailproperty = array(
		'href'=>'index.php?com=pr_validasi&task=list_transaksi&karyawan_id='.$karyawan_id.'&t_id='.$i,
		'title'=>'Detail'
	);
	$detail_button = button_icon( 'b_props.png' , $detailproperty  );
	
	$row[] = array(
		'no'=>position_text_align($i,'center'),
		'ket'=>"Hari kerja ",
		'per'=>"11/".$periode_lalu." - 10/".$periode_ini ,
		'nilai'=>position_text_align($data_absens['hari_kerja_11_10'], 'right' ),
		'satuan'=> 'hari',
		'operasi'=> position_text_align( $detail_button, 'right'),
	);
	
	$i++;
	$detailproperty = array(
		'href'=>'index.php?com=pr_validasi&task=list_transaksi&karyawan_id='.$karyawan_id.'&t_id='.$i,
		'title'=>'Detail'
	);
	$detail_button = button_icon( 'b_props.png' , $detailproperty  );
	
	$row[] = array(
		'no'=>position_text_align($i,'center'),
		'ket'=>"Hari kerja" ,
		'per'=>"1/".$periode_lalu." - ".$tgl_akhir."/".$periode_lalu ,
		'nilai'=>position_text_align($data_absens['hari_kerja_1_31'], 'right' ),
		'satuan'=> 'hari',
		'operasi'=> position_text_align( $detail_button, 'right'),
	);
	
	$i++;
	$detailproperty = array(
		'href'=>'index.php?com=pr_validasi&task=list_transaksi&karyawan_id='.$karyawan_id.'&t_id='.$i,
		'title'=>'Detail'
	);
	$detail_button = button_icon( 'b_props.png' , $detailproperty  );
	
	$row[] = array(
		'no'=>position_text_align($i,'center'),
		'ket'=>"Lembur Otomatis" ,
		'per'=>"11/".$periode_lalu." - 10/".$periode_ini ,
		'nilai'=>position_text_align($data_absens['lembur_otomatis'], 'right' ),
		'satuan'=> 'jam',
		'operasi'=> position_text_align( $detail_button, 'right'),
	);

	$i++;
	$detailproperty = array(
		'href'=>'index.php?com=pr_validasi&task=list_transaksi&karyawan_id='.$karyawan_id.'&t_id='.$i,
		'title'=>'Detail'
	);
	$detail_button = button_icon( 'b_props.png' , $detailproperty  );
	
	$row[] = array(
		'no'=>position_text_align($i,'center'),
		'ket'=>"Jumlah Jam Lembur" ,
		'per'=>"11/".$periode_lalu." - 10/".$periode_ini ,
		'nilai'=>position_text_align($data_absens['lembur_jumlah_jam'], 'right' ),
		'satuan'=> 'jam',
		'operasi'=> position_text_align( $detail_button, 'right'),
	);	

	$i++;
	$detailproperty = array(
		'href'=>'index.php?com=pr_validasi&task=list_transaksi&karyawan_id='.$karyawan_id.'&t_id='.$i,
		'title'=>'Detail'
	);
	$detail_button = button_icon( 'b_props.png' , $detailproperty  );

	$row[] = array(
		'no'=>position_text_align($i,'center'),
		'ket'=>"Total Pengali Lembur" ,
		'per'=>"11/".$periode_lalu." - 10/".$periode_ini ,
		'nilai'=>position_text_align($data_absens['hourpay'], 'right' ),
		'satuan'=> 'X',
		'operasi'=> position_text_align( $detail_button, 'right'),
	);	
	
	$i++;
	$detailproperty = array(
		'href'=>'index.php?com=pr_validasi&task=list_transaksi&karyawan_id='.$karyawan_id.'&t_id='.$i,
		'title'=>'Detail'
	);
	$detail_button = button_icon( 'b_props.png' , $detailproperty  );

	$row[] = array(
		'no'=>position_text_align($i,'center'),
		'ket'=>"Lembur > 4 jam" ,
		'per'=>"1/".$periode_lalu." - ".$tgl_akhir."/".$periode_lalu ,
		'nilai'=>position_text_align($data_absens['lembur_lebih4jam'], 'right' ),
		'satuan'=> 'hari',
		'operasi'=> position_text_align( $detail_button, 'right'),
	);			


	$i++;
	$detailproperty = array(
		'href'=>'index.php?com=pr_validasi&task=list_transaksi&karyawan_id='.$karyawan_id.'&t_id='.$i,
		'title'=>'Detail'
	);
	$detail_button = button_icon( 'b_props.png' , $detailproperty  );

	$row[] = array(
		'no'=>position_text_align($i,'center'),
		'ket'=>"Potong Absen" ,
		'per'=>"11/".$periode_lalu." - 10/".$periode_ini ,
		'nilai'=>position_text_align($data_absens['potong_absen_jam'], 'right' ),
		'satuan'=> 'jam',
		'operasi'=> position_text_align( $detail_button, 'right'),
	);	

	
	$i++;
	$detailproperty = array(
		'href'=>'index.php?com=pr_validasi&task=list_transaksi&karyawan_id='.$karyawan_id.'&t_id='.$i,
		'title'=>'Detail'
	);
	$detail_button = button_icon( 'b_props.png' , $detailproperty  );

	$row[] = array(
		'no'=>position_text_align($i,'center'),
		'ket'=>"Potongan Insentif" ,
		'per'=>"1/".$periode_lalu." - ".$tgl_akhir."/".$periode_lalu ,
		'nilai'=>position_text_align($data_absens['insentif_pot_hari_1_31'], 'right' ),
		'satuan'=> 'hari',
		'operasi'=> position_text_align( $detail_button, 'right'),
	);	
	
	$i++;
	$detailproperty = array(
		'href'=>'index.php?com=pr_validasi&task=list_transaksi&karyawan_id='.$karyawan_id.'&t_id='.$i,
		'title'=>'Detail'
	);
	$detail_button = button_icon( 'b_props.png' , $detailproperty  );
	$row[] = array(
		'no'=>" " ,
		'ket'=>" " ,
		'per'=>" " ,
		'nilai'=>position_text_align($data_absens['insentif_pot_jam_1_31'], 'right' ),
		'satuan'=> 'jam',
		'operasi'=> position_text_align( $detail_button, 'right'),
	);	

	$row[] = array(
		'no'=>" " ,
		'ket'=>" " ,
		'per'=>" " ,
		'nilai'=>position_text_align($data_absens['insentif_pot_menit_1_31'], 'right' ),
		'satuan'=> 'menit',
		'operasi'=> position_text_align( $detail_button, 'right'),
	);	
	
	$i++;
	$detailproperty = array(
		'href'=>'index.php?com=pr_validasi&task=list_transaksi&karyawan_id='.$karyawan_id.'&t_id='.$i,
		'title'=>'Detail'
	);
	$detail_button = button_icon( 'b_props.png' , $detailproperty  );
/*
	$row[] = array(
		'no'=>position_text_align($i,'center'),
		'ket'=>"Lembur > 56 jam" ,
		'per'=>"1/".$periode_lalu." - ".$tgl_akhir."/".$periode_lalu ,
		'nilai'=>position_text_align($data_absens['lembur_lebih56jam'], 'right' ),
		'satuan'=> 'hari',
		'operasi'=> position_text_align( $detail_button, 'right'),
	);	
*/
	$row[] = array(
		'no'=>position_text_align($i,'center'),
		'ket'=>"Lembur <= 56 jam" ,
		'per'=>"1/".$periode_lalu." - ".$tgl_akhir."/".$periode_lalu ,
		'nilai'=>position_text_align($data_absens['hourpay_56'], 'right' ),
		'satuan'=> 'X',
		'operasi'=> position_text_align( $detail_button, 'right'),
	);	

	$i++;
	$detailproperty = array(
		'href'=>'index.php?com=pr_validasi&task=list_transaksi&karyawan_id='.$karyawan_id.'&t_id='.$i,
		'title'=>'Detail'
	);
	$detail_button = button_icon( 'b_props.png' , $detailproperty  );

	$row[] = array(
		'no'=>position_text_align($i,'center'),
		'ket'=>"Jasa On Call" ,
		'per'=>"11/".$periode_lalu." - 10/".$periode_ini ,
		'nilai'=>position_text_align(rp_format($data_absens['cito_11_10']), 'right' ),
		'satuan'=> 'rupiah',
		'operasi'=> position_text_align( $detail_button, 'right'),
	);			

	$i++;
	$detailproperty = array(
		'href'=>'index.php?com=pr_validasi&task=list_transaksi&karyawan_id='.$karyawan_id.'&t_id='.$i,
		'title'=>'Detail'
	);
	$detail_button = button_icon( 'b_props.png' , $detailproperty  );

	$row[] = array(
		'no'=>position_text_align($i,'center'),
		'ket'=>"Jasa On Call > 4jam" ,
		'per'=>"11/".$periode_lalu." - 10/".$periode_ini ,
		'nilai'=>position_text_align($data_absens['cito_lebih4jam'], 'right' ),
		'satuan'=> 'jam',
		'operasi'=> position_text_align( $detail_button, 'right'),
	);	

	$i++;
	$detailproperty = array(
		'href'=>'index.php?com=pr_validasi&task=list_transaksi&karyawan_id='.$karyawan_id.'&t_id='.$i,
		'title'=>'Detail'
	);
	$detail_button = button_icon( 'b_props.png' , $detailproperty  );

	$row[] = array(
		'no'=>position_text_align($i,'center'),
		'ket'=>"Potong Transport" ,
		'per'=>"11/".$periode_lalu." - 10/".$periode_ini ,
		'nilai'=>position_text_align($data_absens['potong_transport'], 'right' ),
		'satuan'=> 'hari',
		'operasi'=> position_text_align( $detail_button, 'right'),
	);	

	
	$datas = table_rows($row);
	$karyawan = loaddata_karyawan($karyawan_id);
	$pro =   karyawan_header_detail($karyawan  );
	$view ='<table width="90%" cellspacing="0" cellpadding="4"><tr>'; 
	$view .= form_header( "..." , "..."  );
	$view .= '<tr><td><td><div style="width:100%;text-align:right;">
	<input type="button" value="Back" class="main_button" onclick="javascript:location.href=\'index.php?com=pr_validasi\'"/></div></td></tr>'   ; 
	return  $pro.$view. table_builder($header , $datas ,  3 , false );
}

function list_transaksi($karyawan_id, $t_id){
	$periode_id=get_periode_gaji() ;
	$periode = my_get_data_by_id('pr_periode','periode_id',$periode_id);
	$month = date('m',strtotime($periode['tanggal']));
	$year = date('Y',strtotime($periode['tanggal']));
	$periode_ini=$month.'/'.$year ;
	if($month==1){
		$month=12;
		$year--;
	}else{
		$month--;
	}	
	$periode_lalu=sprintf( '%02d',$month).'/'.$year ;

	$periode_absen_id =get_periode_absen();
	$last_periode_id=get_last_periode_id($periode_id) ;
	$periodes = my_get_data_by_id('pr_periode','periode_id',$periode_id);
	$bulan = (int) date('m' , strtotime($periodes['tanggal']));
	$tahun = $periodes['tahun'] ;
	$enddate_11_10=$tahun.'-'.sprintf( '%02d',$bulan) .'-10';
	if($bulan =='01' ){
		$bulan = '12';
		$tahun-- ;	
	}else{
		$bulan-- ;
	}		
	$startdate_11_10=$tahun.'-'.sprintf( '%02d',$bulan) .'-11';	
	$startdate_01_31=$tahun.'-'.sprintf( '%02d',$bulan) .'-01';	
	$tgl_akhir=date('d', strtotime(get_last_date_by_month($tahun,$bulan))) ;
	$enddate_01_31=$tahun.'-'.sprintf( '%02d',$bulan) .'-'.$tgl_akhir;
	
/*
		1=hari_kerja_11_10
		2=hari_kerja_1_31
		3=lembur_otomatis
		4=lembur_jumlah_jam	
		5=hourpay	
		6=lembur_lebih4jam
		7=potong_absen_jam
		8=insentif_pot_jam_1_31
		9=lembur_lebih56jam
		hourpay_56
		10=cito_11_10
		11=cito_lebih4jam
*/
	
	$lembur_jam=$lembur_lebih4jam=0;
	$lembur_jumlah_jam=$hourpay=$hourpay_56=$nact=$nact1= 0;

	if($t_id==4){
		$header = array(
				'#'=>array('style'=>'text-align:center;border-bottom:2px solid;width:5%'),  
				'Tanggal'=>array('style'=>'text-align:left;border-bottom:2px solid;width:35%'),  
				'Dari Jam'=>array('style'=>'text-align:left;border-bottom:2px solid;width:15%'),  
				'Sampai Jam'=>array('style'=>'text-align:left;border-bottom:2px solid;width:15%'),  
				'Jam Lembur'=>array('style'=>'text-align:right;border-bottom:2px solid;width:15%'),  
				'Total Jam'=>array('style'=>'text-align:right;border-bottom:2px solid;width:15%'),  
			);				
	}elseif($t_id==5){
		$header = array(
				'#'=>array('style'=>'text-align:center;border-bottom:2px solid;width:5%'),  
				'Tanggal'=>array('style'=>'text-align:left;border-bottom:2px solid;width:35%'),  
				'Dari Jam'=>array('style'=>'text-align:left;border-bottom:2px solid;width:15%'),  
				'Sampai Jam'=>array('style'=>'text-align:left;border-bottom:2px solid;width:15%'),  
				'Jam Lembur'=>array('style'=>'text-align:right;border-bottom:2px solid;width:10%'),  
				'Pengali Lembur'=>array('style'=>'text-align:right;border-bottom:2px solid;width:10%'),  
				'Total Pengali'=>array('style'=>'text-align:right;border-bottom:2px solid;width:10%'),  
			);	
	}elseif($t_id==6){
		$header = array(
				'#'=>array('style'=>'text-align:center;border-bottom:2px solid;width:5%'),  
				'Tanggal'=>array('style'=>'text-align:left;border-bottom:2px solid;width:35%'),  
				'Jumlah Jam Lembur'=>array('style'=>'text-align:right;border-bottom:2px solid;width:20%'),  
				'Lembur > 4 Jam'=>array('style'=>'text-align:right;border-bottom:2px solid;width:20%'),  
				'Total'=>array('style'=>'text-align:right;border-bottom:2px solid;width:20%'),  
			);	
	}elseif($t_id==7){
		$header = array(
				'#'=>array('style'=>'text-align:center;border-bottom:2px solid;width:5%'),  
				'Tanggal'=>array('style'=>'text-align:left;border-bottom:2px solid;width:35%'),  
				'Dari Jam'=>array('style'=>'text-align:left;border-bottom:2px solid;width:15%'),  
				'Sampai Jam'=>array('style'=>'text-align:left;border-bottom:2px solid;width:15%'),  
				'Jumlah Jam'=>array('style'=>'text-align:right;border-bottom:2px solid;width:15%'),  
				'Total Jam'=>array('style'=>'text-align:right;border-bottom:2px solid;width:15%'),  
			);	
	}elseif($t_id==9){
		$header = array(
				'#'=>array('style'=>'text-align:center;border-bottom:2px solid;width:5%'),  
				'Tanggal'=>array('style'=>'text-align:left;border-bottom:2px solid;width:35%'),  
				'Dari Jam'=>array('style'=>'text-align:left;border-bottom:2px solid;width:10%'),  
				'Sampai Jam'=>array('style'=>'text-align:left;border-bottom:2px solid;width:10%'),  
				'Jumlah Jam'=>array('style'=>'text-align:right;border-bottom:2px solid;width:10%'),  
				'Total Jam'=>array('style'=>'text-align:right;border-bottom:2px solid;width:10%'),  
				'Jumlah Menit'=>array('style'=>'text-align:right;border-bottom:2px solid;width:10%'),  
				'Total menit'=>array('style'=>'text-align:right;border-bottom:2px solid;width:10%'),  
			);		

	}elseif($t_id==10){
		$header = array(
				'#'=>array('style'=>'text-align:center;border-bottom:2px solid;width:5%'),  
				'Tanggal'=>array('style'=>'text-align:left;border-bottom:2px solid;width:35%'),  
				'Jumlah Jam'=>array('style'=>'text-align:right;border-bottom:2px solid;width:15%'),  
				'Calc 1'=>array('style'=>'text-align:right;border-bottom:2px solid;width:15%'),  
				'Calc 2'=>array('style'=>'text-align:right;border-bottom:2px solid;width:15%'),  
				'Hour Pay'=>array('style'=>'text-align:right;border-bottom:2px solid;width:15%'),  
			);		
	}elseif($t_id==11){
		$header = array(
				'#'=>array('style'=>'text-align:center;border-bottom:2px solid;width:5%'),  
				'Tanggal'=>array('style'=>'text-align:left;border-bottom:2px solid;width:25%'),  
				'Jam'=>array('style'=>'text-align:right;border-bottom:2px solid;width:10%'),  
				'Total Jam'=>array('style'=>'text-align:right;border-bottom:2px solid;width:10%'),  
				'Rp'=>array('style'=>'text-align:right;border-bottom:2px solid;width:15%'),  
				'Total Rp'=>array('style'=>'text-align:right;border-bottom:2px solid;width:15%'),  
				'> 4 Jam'=>array('style'=>'text-align:right;border-bottom:2px solid;width:10%'),  
				'Total > 4 jam'=>array('style'=>'text-align:right;border-bottom:2px solid;width:10%'),  
			);	
			
	}else{
		$header = array(
			'#'=>array('style'=>'text-align:center;border-bottom:2px solid;width:5%'),  
			'Tanggal'=>array('style'=>'text-align:left;border-bottom:2px solid;width:95%'),  
		);
	}
	$no=0;
	$row = array(); 
	if(	$t_id==1 ) {  //hari_kerja_11_10
		$judul="Hari kerja 11/".$periode_lalu." - 10/".$periode_ini ;
		$query = "SELECT status_absen_id,field_tgl,if(substr(field_tgl,5,2)<11,1,0) as dummy  
			FROM a_realisasi_log 
			WHERE karyawan_id={$karyawan_id} 
			AND periode_id={$periode_id} 
			ORDER BY dummy, field_tgl"
		;	
		$res1 = my_query($query); 	
		while($ey1 = my_fetch_array($res1)){
			$status_absens=my_get_data_by_id('a_status_absen','status_absen_id',$ey1['status_absen_id']) ;
			if($status_absens['hari_kerja']=="Y"){
				$no++;
				$tgl = (int) substr($ey1['field_tgl'],4,2) ;
				$row[] = array(
					'no'=>position_text_align($no,'center'),
					'tgl'=>sprintf( '%02d',$tgl).'/'.( $tgl < 11 ? $periode_ini : $periode_lalu) ,
				);	
			}
		}
	}elseif( $t_id==2 ){ //hari_kerja_1_31	
		$judul="Hari kerja 1/".$periode_lalu." - ".$tgl_akhir."/".$periode_lalu ;

		$query = "SELECT * FROM a_realisasi_log 
			WHERE karyawan_id=".$karyawan_id." 
			AND	periode_id=".($last_periode_id)." 
			AND field_tgl IN (
			'tgl_01', 
			'tgl_02', 
			'tgl_03', 
			'tgl_04', 
			'tgl_05', 
			'tgl_06', 
			'tgl_07', 
			'tgl_08', 
			'tgl_09', 
			'tgl_10' )
			ORDER BY field_tgl"
		;	
		$res2 = my_query($query); 	
		while($ey2 = my_fetch_array($res2)){
			$status_absens=my_get_data_by_id('a_status_absen','status_absen_id',$ey2['status_absen_id']) ;
			if($status_absens['hari_kerja']=="Y"){
				$no++;
				$row[] = array(
					'no'=>position_text_align($no,'center'),
					'tgl'=>substr($ey2['field_tgl'],4,2).'/'.$periode_lalu,
				);	
			}		
		}	
		$query = "SELECT * FROM a_realisasi_log 
				WHERE karyawan_id=".$karyawan_id." 
				AND periode_id=".$periode_id." 
				AND field_tgl NOT IN (
				'tgl_01', 
				'tgl_02', 
				'tgl_03', 
				'tgl_04', 
				'tgl_05', 
				'tgl_06', 
				'tgl_07', 
				'tgl_08', 
				'tgl_09', 
				'tgl_10' )
				ORDER BY field_tgl"
		;	
		$res1 = my_query($query); 	
		while($ey1 = my_fetch_array($res1)){
			$status_absens=my_get_data_by_id('a_status_absen','status_absen_id',$ey1['status_absen_id']) ;			 
			if($status_absens['hari_kerja']=="Y"){
				$no++;
				$row[] = array(
					'no'=>position_text_align($no,'center'),
					'tgl'=>substr($ey1['field_tgl'],4,2).'/'.$periode_lalu,
				);	
			}
		}

	}elseif( $t_id==3 ){ //lembur_otomatis
		$judul="Lembur Otomatis 11/".$periode_lalu." - 10/".$periode_ini ;
		$query = "SELECT status_absen_id,field_tgl,if(substr(field_tgl,5,2)<11,1,0) as dummy  
			FROM a_realisasi_log 
			WHERE karyawan_id={$karyawan_id} 
			AND periode_id={$periode_id} 
			ORDER BY dummy, field_tgl"
		;	

		$res1 = my_query($query); 	
		while($ey1 = my_fetch_array($res1)){
			$status_absens=my_get_data_by_id('a_status_absen','status_absen_id',$ey1['status_absen_id']) ;
			if($status_absens['lembur_otomatis']=="Y"){
				$tgl = (int) substr($ey1['field_tgl'],4,2) ;
				$no++;
				$row[] = array(
					'no'=>position_text_align($no,'center'),
					'tgl'=>sprintf( '%02d',$tgl).'/'.( $tgl < 11 ? $periode_ini : $periode_lalu) ,
				);	
			}
		}		
	}elseif( $t_id==4 ){ //lembur_jumlah_jam
		$judul="Jumlah Jam Lembur 11/".$periode_lalu." - 10/".$periode_ini ;

		$query = "SELECT *  
				FROM a_spl 
				WHERE karyawan_id={$karyawan_id}  
				AND tanggal BETWEEN '".$startdate_01_31."' AND '".$enddate_11_10."'
				ORDER BY tanggal
				" ;
		$res = my_query($query);
		$tjam=$thourpay=0;
		while($ey1 = my_fetch_array($res)){
			$no++;	
			$tjam+=$ey1['jumlah_jam'];
			$thourpay+=$ey1['hourpay'];
			$row[] = array(
				'no'=>position_text_align($no,'center'),
				'tgl'=>date( "d-m-Y" , strtotime($ey1['tanggal'].' 00:00:00')),
				'dari_jam'=>$ey1['dari_jam'],
				'sampai_jam'=>$ey1['sampai_jam'],
				'jam'=> position_text_align ($ey1['jumlah_jam'] ,'right'),   
				'tjam'=> position_text_align ($tjam ,'right'),   
			);		
		}
	}elseif( $t_id==5 ){ //pengali_lembur
		$judul="Total Pengali Lembur 11/".$periode_lalu." - 10/".$periode_ini ;
		$query = "SELECT *  
				FROM a_spl 
				WHERE karyawan_id={$karyawan_id}
				AND tanggal BETWEEN '".$startdate_01_31."' AND '".$enddate_11_10."'
				ORDER BY tanggal
				" ;
		$res = my_query($query);
		$tjam=$thourpay=0;
		while($ey1 = my_fetch_array($res)){
			$no++;	
			$tjam+=$ey1['jumlah_jam'];
			$thourpay+=$ey1['hourpay'];
			$row[] = array(
				'no'=>position_text_align($no,'center'),
				'tgl'=>date( "d-m-Y" , strtotime($ey1['tanggal'].' 00:00:00')),
				'dari_jam'=>$ey1['dari_jam'],
				'sampai_jam'=>$ey1['sampai_jam'],
				'jam'=> position_text_align ($ey1['jumlah_jam'] ,'right'),   				
				'hourpay'=>position_text_align($ey1['hourpay'],'right'),
				'thourpay'=>position_text_align($thourpay,'right'),
			);		
		}		
	}elseif( $t_id==6 ){ 
		$judul="Lembur > 4 jam 1/".$periode_lalu." - ".$tgl_akhir."/".$periode_lalu;
		$query = "SELECT tanggal,sum(hourpay) as hourpay, sum(jumlah_jam) as jumlah_jam  
			FROM a_spl 
			WHERE karyawan_id={$karyawan_id}
			AND tanggal BETWEEN '".$startdate_01_31."' AND '".$enddate_01_31."'
			GROUP BY tanggal ORDER BY DAY(tanggal)
		" ;
		$res = my_query($query);
		$lembur_jam=$lembur_lebih4jam=$total=0;
		while($ey1 = my_fetch_array($res)){
			$lembur_jam=$ey1['jumlah_jam'] ;
			if( $lembur_jam  >= 16){
				$lembur_lebih4jam=3 ;
			}elseif( $lembur_jam  >= 12){	
				$lembur_lebih4jam=2 ;
			}elseif( $lembur_jam  >=4){	
				$lembur_lebih4jam=1 ;
			}else{
				$lembur_lebih4jam=0 ;
			}
			$total+=$lembur_lebih4jam ;
			if($lembur_lebih4jam>0){
				$no++;	
				$row[] = array(
					'no'=>position_text_align($no,'center'),
					'tgl'=>date( "d-m-Y" , strtotime($ey1['tanggal'].' 00:00:00')),
					'lembur_jam'=> position_text_align ($lembur_jam,'right'),   	
					'lembur_lebih4jam'=>position_text_align ($lembur_lebih4jam.' hari','right'),   	
					'total'=> position_text_align ($total.' hari','right'),   				
				);		
			}	
		}
			
	}elseif( $t_id==7 ){ 
		$judul="Potong Absen 11/".$periode_lalu." - 10/".$periode_ini;
		$query = "SELECT status_absen_id,field_tgl,if(substr(field_tgl,5,2)<11,1,0) as dummy  
			FROM a_realisasi_log 
			WHERE karyawan_id={$karyawan_id} 
			AND periode_id={$periode_id} 
			ORDER BY dummy, field_tgl"
		;	
		$res1 = my_query($query); 	
		$potong_absen_jam=$total=0;
		while($ey1 = my_fetch_array($res1)){
			$status_absens=my_get_data_by_id('a_status_absen','status_absen_id',$ey1['status_absen_id']) ;
			if((int) $ey1['status_absen_id']==16 ){  //nanti direvisi status absen + kolom potong absensi
				$tgl = (int) substr($ey1['field_tgl'],4,2) ;
				$potong_absen_jam=8;
				$total+=$potong_absen_jam ;
				$no++;	
				$row[] = array(
					'no'=>position_text_align($no,'center'),
					'tgl'=>sprintf( '%02d',$tgl).'/'.( $tgl < 11 ? $periode_ini : $periode_lalu) ,
					'dari_jam'=>'-',
					'sampai_jam'=>'-',
					'jam'=> position_text_align ($potong_absen_jam ,'right'),   				
					'total'=>position_text_align($total,'right'),
				);					
			}
		}
		// HITUNG ABSEN
		$query = "
			SELECT * FROM a_surat_ijin	WHERE 
			tanggal BETWEEN '".$startdate_11_10."' AND '".$enddate_11_10."' 
			AND karyawan_id=".$karyawan_id." 
			AND rekomendasi='T'"
		;
		$res = my_query($query);
		while($ey = my_fetch_array($res)){
			if( $ey['full_day']=='Y'){
			}else{
				if($ey['jam_sampai']>$ey['jam_dari']){
					$jam_dari=$ey['jam_dari'];
					$jam_sampai=$ey['jam_sampai'];
				}else{
					$jam_dari=$ey['jam_sampai'];
					$jam_sampai=$ey['jam_dari'];
				}
				$jam_menit=strtotime('2001-01-01 '.time_min($jam_sampai,$jam_dari));
				$potong_absen_jam=(int) date("H",$jam_menit );
				$potong_absen_jam+=(int) date("i",$jam_menit )/60;
				$total+=$potong_absen_jam ;
				$no++;	
				$row[] = array(
					'no'=>position_text_align($no,'center'),
					'tgl'=>date( "d-m-Y" , strtotime($ey1['tanggal'].' 00:00:00')),
					'dari_jam'=>'-',
					'sampai_jam'=>'-',
					'jam'=> position_text_align ($potong_absen_jam ,'right'),   				
					'total'=>position_text_align($total,'right'),
				);					
			}
		}		
	}elseif( $t_id==8 ){ 
		$judul="Potongan Insentif (Hari) 1/".$periode_lalu." - ".$tgl_akhir."/".$periode_lalu;

		$query = "SELECT * FROM a_realisasi_log 
			WHERE karyawan_id=".$karyawan_id." 
			AND	periode_id=".($last_periode_id)." 
			AND field_tgl IN (
			'tgl_01', 
			'tgl_02', 
			'tgl_03', 
			'tgl_04', 
			'tgl_05', 
			'tgl_06', 
			'tgl_07', 
			'tgl_08', 
			'tgl_09', 
			'tgl_10' )
			ORDER BY field_tgl"
		;	
		$res2 = my_query($query); 	
		while($ey2 = my_fetch_array($res2)){
			$status_absens=my_get_data_by_id('a_status_absen','status_absen_id',$ey2['status_absen_id']) ;
			if($status_absens['potong_insentif']=="Y"){
				$no++;
				$row[] = array(
					'no'=>position_text_align($no,'center'),
					'tgl'=>substr($ey2['field_tgl'],4,2).'/'.$periode_lalu,
				);	
			}		
		}	
		$query = "SELECT * FROM a_realisasi_log 
				WHERE karyawan_id=".$karyawan_id." 
				AND periode_id=".$periode_id." 
				AND field_tgl NOT IN (
				'tgl_01', 
				'tgl_02', 
				'tgl_03', 
				'tgl_04', 
				'tgl_05', 
				'tgl_06', 
				'tgl_07', 
				'tgl_08', 
				'tgl_09', 
				'tgl_10' )
				ORDER BY field_tgl"
		;	
		$res1 = my_query($query); 	
		while($ey1 = my_fetch_array($res1)){
			$status_absens=my_get_data_by_id('a_status_absen','status_absen_id',$ey1['status_absen_id']) ;			 
			if($status_absens['potong_insentif']=="Y"){
				$no++;
				$row[] = array(
					'no'=>position_text_align($no,'center'),
					'tgl'=>substr($ey1['field_tgl'],4,2).'/'.$periode_lalu,
				);	
			}
		}	
	}elseif( $t_id==9 ){ 
		$judul="Potongan Insentif (Jam & Menit) 1/".$periode_lalu." - ".$tgl_akhir."/".$periode_lalu;
		// HITUNG POTONGAN INSENTIF JAM & MENIT
		$query = "
			SELECT * FROM a_surat_ijin	WHERE MONTH(tanggal)='".$bulan."'
			AND YEAR(tanggal)='".$tahun."' AND karyawan_id={$karyawan_id}  
			AND potong_insentif='Y' AND full_day<>'Y'"
		;
		$total_jam=$total_menit=0 ;
		$res = my_query($query);
		while($ey = my_fetch_array($res)){
			if($ey['jam_sampai']>$ey['jam_dari']){
				$jam_dari=$ey['jam_dari'];
				$jam_sampai=$ey['jam_sampai'];
			}else{
				$jam_dari=$ey['jam_sampai'];
				$jam_sampai=$ey['jam_dari'];
			}
			$jam_menit=strtotime('2001-01-01 '.time_min($jam_sampai,$jam_dari));
			$insentif_pot_jam_1_31=(int) date("H",$jam_menit );
			$insentif_pot_menit_1_31=(int) date("i",$jam_menit );
			$total_jam+=$insentif_pot_jam_1_31 ;
			$total_menit+=$insentif_pot_menit_1_31 ;
			$no++;	
			$row[] = array(
				'no'=>position_text_align($no,'center'),
				'tgl'=>date( "d-m-Y" , strtotime($ey['tanggal'].' 00:00:00')),
				'dari_jam'=>$jam_dari,
				'sampai_jam'=>$jam_sampai,
				'jam'=> position_text_align ($insentif_pot_jam_1_31 ,'right'),   				
				'total_jam'=>position_text_align($total_jam,'right'),
				'menit'=> position_text_align ($insentif_pot_menit_1_31 ,'right'),   				
				'total_menit'=>position_text_align($total_menit,'right'),
			);									
				
		}
	}elseif( $t_id==10 ){ 
		$judul="Lembur <= 56 jam 1/".$periode_lalu." - ".$tgl_akhir."/".$periode_lalu;
		
		$query = "SELECT tanggal,sum(hourpay) as hourpay, sum(jumlah_jam) as jumlah_jam  
				FROM a_spl 
				WHERE karyawan_id={$karyawan_id}   
				AND tanggal BETWEEN '".$startdate_11_10."' AND '".$enddate_11_10."'
				GROUP BY tanggal ORDER BY DAY(tanggal)
				" ;
		$res = my_query($query);
		$hourpay_56=$nact=$nact1=0;
		while($ey1 = my_fetch_array($res)){
			if($nact+$ey1['jumlah_jam']<=56){
				$nact+=$ey1['jumlah_jam'];
				$hourpay_56+=$ey1['hourpay'];
			}else{	
				$nact1+=$ey1['jumlah_jam'];
			}			
			$no++;	
			$row[] = array(
				'no'=>position_text_align($no,'center'),
				'tgl'=>date( "d-m-Y" , strtotime($ey1['tanggal'].' 00:00:00')),
				'jumlah_jam'=>position_text_align ($ey1['jumlah_jam'],'right'), 
				'nact'=>position_text_align ($nact,'right'), 
				'nact1'=> position_text_align ($nact1 ,'right'),   				
				'hour_pay'=>position_text_align($hourpay_56,'right'),
			);					
			
		}

		if($nact1<>0 AND $nact <=56){
			if(($nact1+$nact) > 56){
				$hourpay_56+=((56-$nact)* 2 - 0.5 );
			}else{	
				$hourpay_56+=($nact1* 2 - 0.5 );
			}
			$no++;	
			$row[] = array(
				'no'=>position_text_align($no,'center'),
				'tgl'=>date( "d-m-Y" , strtotime($ey1['tanggal'].' 00:00:00')),
				'jumlah_jam'=>position_text_align ($ey1['jumlah_jam'],'right'), 
				'nact'=>position_text_align ($nact,'right'), 
				'nact1'=> position_text_align ($nact1 ,'right'),   				
				'hour_pay'=>position_text_align($hourpay_56,'right'),
			);					
		}
		if($no>0){
			$hourpay_56=round($hourpay_56);
			$row[] = array(
				'no'=>' ',
				'tgl'=>'Dibulatkan',
				'jumlah_jam'=>' ', 
				'nact'=>' ', 
				'nact1'=> ' ',   				
				'hour_pay'=>position_text_align($hourpay_56,'right'),
			);					
		}
		
	}elseif( $t_id==11 ){ 
		$judul="Jasa On Call 11/".$periode_lalu." - 10/".$periode_ini;	
		// HITUNG POTONGAN INSENTIF JAM & MENIT
		$query = "SELECT dua_jam,empat_jam from woc_tarif a 
			INNER JOIN kekaryawanan b ON a.golongan_jabatan_id=b.golongan_jabatan_id 
			WHERE b.karyawan_id = {$karyawan_id }";	
		$tarifs = my_fetch_array(my_query($query));

		$query = "SELECT tanggal,jumlah_jam FROM work_on_call_detail a 
			INNER JOIN work_on_call b ON a.work_on_call_id=b.work_on_call_id 	
			WHERE a.karyawan_id={$karyawan_id} 
			AND b.tanggal BETWEEN '".$startdate_11_10."' AND '".$enddate_11_10."' 
			ORDER BY b.tanggal " ;
		$res = my_query($query);

		$tgl=false;
		$total_11_10=$cito_jam=$cito_lebih4jam=$total_lebih4jam=0;
		while($ey = my_fetch_array($res)){
			$cito_11_10=$cito_lebih4jam=0;
			if( (int) $ey['jumlah_jam']  < 4){
				$cito_11_10=$ey['jumlah_jam']*$tarifs['dua_jam'] ;
			}else{
				$cito_11_10=$ey['jumlah_jam']*$tarifs['empat_jam'] ;
			}
			//tambahan u makan
			if($ey['tanggal']==$tgl){
			}else{
				if( $cito_jam  >= 4){
					$cito_lebih4jam=1 ;
				}			
				$tgl=$ey['tanggal'] ;
				$cito_jam=0;
			}
			$total_lebih4jam+=$cito_lebih4jam ;
			$cito_jam+=$ey['jumlah_jam'];
			if($cito_11_10<>0){
				$total_11_10+=$cito_11_10 ;
				$no++;	
				$row[] = array(
					'no'=>position_text_align($no,'center'),
					'tgl'=>date( "d-m-Y" , strtotime($ey['tanggal'].' 00:00:00')),
					'jam'=>position_text_align ($ey['jumlah_jam'],'right'), 
					'total_jam'=>position_text_align ($cito_jam,'right'), 
					'rupiah'=>position_text_align (rp_format($cito_11_10),'right'), 
					'total_rupiah'=>position_text_align(rp_format($total_11_10),'right'),
					'cito_lebih4jam'=> position_text_align ($cito_lebih4jam ,'right'),   				
					'total_lebih4jam'=> position_text_align ($total_lebih4jam ,'right'),   				
				);					
			}	
		}
		if($tgl){ //data terakhir
			if( $cito_jam  >= 4){
				$cito_lebih4jam=1 ;
				$total_lebih4jam+=$cito_lebih4jam ;
				$no++;	
				$row[] = array(
					'no'=>position_text_align($no,'center'),
					'tgl'=>date( "d-m-Y" , strtotime($ey['tanggal'].' 00:00:00')),
					'jam'=>position_text_align ($ey['jumlah_jam'],'right'), 
					'total_jam'=>position_text_align ($cito_jam,'right'), 
					'rupiah'=>position_text_align (rp_format($cito_11_10),'right'), 
					'total_rupiah'=>position_text_align(rp_format($total_11_10),'right'),
					'cito_lebih4jam'=> position_text_align ($cito_lebih4jam ,'right'),   				
					'total_lebih4jam'=> position_text_align ($total_lebih4jam ,'right'),   				
				);					
			}			
		}		
	}elseif( $t_id==13 ){ //potong transport
		$judul="Potong Transport (Hari) 11/".$periode_lalu." - 10/".$periode_ini ;
		$query = "SELECT status_absen_id,field_tgl,if(substr(field_tgl,5,2)<11,1,0) as dummy  
			FROM a_realisasi_log 
			WHERE karyawan_id={$karyawan_id} 
			AND periode_id={$periode_id} 
			ORDER BY dummy, field_tgl"
		;	

		$res1 = my_query($query); 	
		while($ey1 = my_fetch_array($res1)){
			$status_absens=my_get_data_by_id('a_status_absen','status_absen_id',$ey1['status_absen_id']) ;
			if($status_absens['potong_transport']=="Y"){
				$tgl = (int) substr($ey1['field_tgl'],4,2) ;
				$no++;
				$row[] = array(
					'no'=>position_text_align($no,'center'),
					'tgl'=>sprintf( '%02d',$tgl).'/'.( $tgl < 11 ? $periode_ini : $periode_lalu) ,
				);	
			}
		}					
	}	

	$datas = table_rows($row);
	$view  = form_header( "..." , "..."  );
	$view .= form_field_display( '<span class="label_form"> '.$judul.'</span>'   , "<b>Keterangan</b>"    ); 
	
	$menuontop = array(  
		'Back' => array('onclick'=>'javascript:location.href=\'index.php?com=pr_validasi&task=detail_absen&karyawan_id='.$karyawan_id.'\''),
		);
	$printmenu = additional_menu_on_list( $menuontop , '');
	return $view.$printmenu.table_builder($header , $datas ,  3 , false );
}

function list_detail_premi($karyawan_id){
	$periode_id =get_periode_gaji();
	$last_periode_id=get_last_periode_id($periode_id) ;
	$periode = my_get_data_by_id('pr_periode','periode_id',$last_periode_id);
	$bulan = (int) date('m' , strtotime($periode['tanggal']));
	$tahun = (int) date('Y' , strtotime($periode['tanggal']));
	$query  = "SELECT * FROM kes_biaya_kesehatan 
		WHERE karyawan_id = {$karyawan_id} 
		AND MONTH(tanggal)='".$bulan."'
		AND YEAR(tanggal)='".$tahun."'"
	;	
	
	$header = array(
		'#'=>array('style'=>'text-align:center;border-bottom:2px solid;width:5%'),  
		'Tanggal'=>array('style'=>'text-align:center;border-bottom:2px solid;width:10%'),  
		'Nama Pasien'=>array('style'=>'text-align:center;border-bottom:2px solid;width:50%'),   
		'Hub. Keluarga'=>array('style'=>'text-align:center;border-bottom:2px solid;width:15%'),   
		'Unit'=>array('style'=>'text-align:center;border-bottom:2px solid;width:10%'),   
		'Biaya'=>array('style'=>'text-align:right;border-bottom:2px solid;width:15%'),   
	);
	
	$i=0;
	$row= array();
	$result = my_query($query);	
	
	while($ey = my_fetch_array($result)){
		$i++;
		$unit_id= isset( $ey['unit_id']  ) ?  $ey['unit_id']:  0;
		$units=my_get_data_by_id('kes_unit','unit_id', $unit_id) ;
		$row[] = array(
			'no'=>position_text_align($i,'center'),
			'tgl'=> position_text_align ( date( 'd-m-Y' , strtotime($ey['tanggal']) ) ,  'center'), 
			'nama'=> $ey['nama_pasien'] ,
			'hubungan'=>  position_text_align($ey['hubungan_keluarga'] ,'center'),
			'unit'=>  position_text_align ($units['nama_unit'] ,  'center'), 
			'biaya'=> position_text_align( rp_format( $ey['total_biaya']) ,  'right'),  
		);	
	}
	
	$datas = table_rows($row);
	$karyawan = loaddata_karyawan($karyawan_id);
	$pro =   karyawan_header_detail($karyawan  );
	$view ='<table width="90%" cellspacing="0" cellpadding="4"><tr>'; 
	$view .= form_header( "..." , "..."  );
	$view .= '<tr><td><td><div style="width:100%;text-align:right;">
	<input type="button" value="Back" class="main_button" onclick="javascript:location.href=\'index.php?com=pr_validasi\'"/></div></td></tr>'   ; 
	return  $pro.$view. table_builder($header , $datas ,  3 , false );
}
